home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows (5th Edition) / Programming Windows, 5th ed. - Companion CD (097-0002183)(1999).iso / Chap18 / Emf6 / Emf6.c next >
Encoding:
C/C++ Source or Header  |  1998-10-09  |  3.2 KB  |  105 lines

  1. /*-------------------------------------
  2.    EMF6.C -- Enhanced Metafile Demo #6
  3.              (c) Charles Petzold, 1998
  4.   -------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
  9.  
  10. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  11.                     PSTR lpszCmdLine, int iCmdShow)
  12. {
  13.      static TCHAR szAppName[] = TEXT ("EMF6") ;
  14.      HWND         hwnd ;
  15.      MSG          msg ;
  16.      WNDCLASS     wndclass ;
  17.      
  18.      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  19.      wndclass.lpfnWndProc   = WndProc ;
  20.      wndclass.cbClsExtra    = 0 ;
  21.      wndclass.cbWndExtra    = 0 ;
  22.      wndclass.hInstance     = hInstance ;
  23.      wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  24.      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  25.      wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
  26.      wndclass.lpszMenuName  = NULL ;
  27.      wndclass.lpszClassName = szAppName ;
  28.      
  29.      if (!RegisterClass (&wndclass))
  30.      {
  31.           MessageBox (NULL, TEXT ("This program requires Windows NT!"),
  32.                       szAppName, MB_ICONERROR) ;
  33.           return 0 ;
  34.      }
  35.      
  36.      hwnd = CreateWindow (szAppName, TEXT ("Enhanced Metafile Demo #6"),
  37.                           WS_OVERLAPPEDWINDOW,
  38.                           CW_USEDEFAULT, CW_USEDEFAULT,
  39.                           CW_USEDEFAULT, CW_USEDEFAULT,
  40.                           NULL, NULL, hInstance, NULL) ;
  41.      
  42.      ShowWindow (hwnd, iCmdShow) ;
  43.      UpdateWindow (hwnd) ;
  44.      
  45.      while (GetMessage (&msg, NULL, 0, 0))
  46.      {
  47.           TranslateMessage (&msg) ;
  48.           DispatchMessage (&msg) ;
  49.      }
  50.      return msg.wParam ;
  51. }
  52.  
  53. int CALLBACK EnhMetaFileProc (HDC hdc, HANDLETABLE * pHandleTable,
  54.                               CONST ENHMETARECORD * pEmfRecord, 
  55.                               int iHandles, LPARAM pData)
  56. {
  57.      ENHMETARECORD * pEmfr ;
  58.      
  59.      pEmfr = (ENHMETARECORD *) malloc (pEmfRecord->nSize) ;
  60.      
  61.      CopyMemory (pEmfr, pEmfRecord, pEmfRecord->nSize) ;
  62.      
  63.      if (pEmfr->iType == EMR_RECTANGLE)
  64.           pEmfr->iType = EMR_ELLIPSE ;
  65.  
  66.      PlayEnhMetaFileRecord (hdc, pHandleTable, pEmfr, iHandles) ;
  67.      
  68.      free (pEmfr) ;
  69.  
  70.      return TRUE ;
  71. }
  72.  
  73. LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  74. {
  75.      HDC          hdc ;
  76.      HENHMETAFILE hemf ;
  77.      PAINTSTRUCT  ps ;
  78.      RECT         rect ;
  79.      
  80.      switch (message)
  81.      {
  82.      case WM_PAINT:
  83.           hdc = BeginPaint (hwnd, &ps) ;
  84.           
  85.           GetClientRect (hwnd, &rect) ;
  86.           
  87.           rect.left   =     rect.right  / 4 ;
  88.           rect.right  = 3 * rect.right  / 4 ;
  89.           rect.top    =     rect.bottom / 4 ;
  90.           rect.bottom = 3 * rect.bottom / 4 ;
  91.           
  92.           hemf = GetEnhMetaFile (TEXT ("..\\emf3\\emf3.emf")) ;
  93.           
  94.           EnumEnhMetaFile (hdc, hemf, EnhMetaFileProc, NULL, &rect) ;
  95.           DeleteEnhMetaFile (hemf) ;
  96.           EndPaint (hwnd, &ps) ;
  97.           return 0 ;
  98.           
  99.      case WM_DESTROY:
  100.           PostQuitMessage (0) ;
  101.           return 0 ;
  102.      }
  103.      return DefWindowProc (hwnd, message, wParam, lParam) ;
  104. }
  105.